#include <bits/stdc++.h>
using namespace std;
int start[1000005],speed[1005],jly[100005];
int db(int m,int n,int xs){
    int ooo;
    int b=0;
    for(int i=1;i<=m;i++)
        cin>>start[i]>>speed[i]>>ooo;
    for(int i=1;i<=n;i++)
        cin>>jly[i];
    for(int i=1;i<=m;i++){
        if(speed[i]>xs&&start[i]<jly[n])
            b++;
}
    return b;
}
int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int T;
    cin>>T;
    int m,n,road,xs;
    for(int i=1;i<=T;i++){
        cin>>m>>n;
        cin>>road>>xs;
        cout<<db(m,n,xs)<<" "<<n-1;
    }
   return 0;
}
